package com.jic.order.controller.pay;

import com.alibaba.fastjson.JSONObject;
import com.jic.common.base.vo.RestResult;
import com.jic.order.request.PayOrderRequest;
import com.jic.order.service.OrderPayService;
import com.jic.order.utils.XmlUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Slf4j
@Api(tags = {"Feign-支付接口"})
@RequestMapping(value = "orderPay")
@RestController
public class OrderPayController {
    @Autowired
    private OrderPayService orderPayService;

    @ApiOperation(value = "支付接口")
    @PostMapping("/pay")
    RestResult<Map<String,String>> preOrder(@RequestBody PayOrderRequest payOrderRequest, HttpServletRequest request){
        String ip = XmlUtils.getIpAddr(request);
        payOrderRequest.setIp(ip);
        return orderPayService.payOrder(payOrderRequest);
    }
    @ApiOperation(value = "获取卡密因子")
    @PostMapping("/getPwd")
    RestResult<JSONObject> getPwd(@RequestBody JSONObject jsonObject){
        return orderPayService.getPwd(jsonObject);
    }
    @ApiOperation(value = "微众支付查询")
    @PostMapping("/prePayOrderCheck")
    RestResult<String> prePayOrderCheck(@RequestBody PayOrderRequest payOrderRequest){
        orderPayService.prePayOrderCheck(payOrderRequest);
        return null;
    }
    @ApiOperation(value = "微众退款")
    @PostMapping("/refundOrder")
    RestResult<String> refundOrder(@RequestBody PayOrderRequest payOrderRequest){
        orderPayService.refundOrder(payOrderRequest);
        return null;
    }
    @ApiOperation(value = "微众退款查询")
    @PostMapping("/refundOrderCheck")
    RestResult<String> refundOrderCheck(@RequestBody PayOrderRequest payOrderRequest){
        orderPayService.refundOrderCheck(payOrderRequest);
        return null;
    }
}
